new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Enterprise_Type: "",
        page: 1,			//页数
        limit: 10,			//每页数据条数
        token: $.cookie('token')
      },
      formData: {},
      tableData: [],		//表格数据
      total: 1,
      dialogForm: false,
      loading: false,
      title: '',
      multipleSelection: []
    }
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    onSerach() {				//查询方法
      let _this = this
      console.log(_this.form.serachKey)
    },
    addContract() {
      console.log("跳转")
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    getList(data) {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        url: DomainName + "/getAuthenticationInfo",
        data,
        success: function (Result) {
          console.log(Result)
          if (Result.Status == "success") {
            _this.tableData = Result.tableData
            _this.total = parseInt(Result.limit)
            console.log(_this.tableData);
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    agree(row, id) {
      const _this = this
      let message = ''
      if (id == 0) {
        message = '确认继续同意操作吗'
        this.$confirm(message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (!_this.loading) {
            _this.loading = true
            $.ajax({
              type: 'POST',
              url: DomainName + "/GoodsInquiryKeyOriginal",
              data: {
                Primary_Key_Name: 'User_Number', //主键名
                Primary_Key: row.User_Number,
                Data: 'system_user_info',
              },
              success: function (Result) {
                console.log(Result)
                _this.formData = Result[0]
                _this.Update(row, id, '')
              },
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              },
              dataType: "json"
            });
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        })
      } else {
        this.$prompt('请输入拒绝原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({ value }) => {
          if (!_this.loading) {
            _this.loading = true
            $.ajax({
              type: 'POST',
              url: DomainName + "/GoodsInquiryKeyOriginal",
              data: {
                Primary_Key_Name: 'User_Number', //主键名
                Primary_Key: row.User_Number,
                Data: 'system_user_info',
              },
              success: function (Result) {
                console.log(Result)
                _this.formData = Result[0]
                _this.Update(row, id, value)
              },
              complete: function (XMLHttpRequest) {
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              },
              dataType: "json"
            });
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });
        });
      }
    },
    Update(row, id, value) {
      const _this = this
      let message = ''
      let datas = {}
      console.log(row);
      console.log(id);
      if (id == 0) {
        if (this.formData.Authentication_Type == '0') {
          this.formData.Authentication = '0'
          this.formData.Authentication_Type = '2'
        } else if (this.formData.Authentication_Type == '1') {
          this.formData.Authentication = '1'
          this.formData.Authentication_Type = '3'
        }
        datas.User_Number = row.User_Number
        datas.Enterprise_Info_SerialNumber = row.Enterprise_Info_SerialNumber
        datas.Authentication_Status = 0
        datas.Cause = value
        message = '已同意'
      } else {
        if (this.formData.Authentication_Type == '0') {
          this.formData.Authentication_Type = '4'
        } else if (this.formData.Authentication_Type == '1') {
          this.formData.Authentication_Type = '5'
        }
        datas.User_Number = row.User_Number
        datas.Enterprise_Info_SerialNumber = row.Enterprise_Info_SerialNumber
        datas.Authentication_Status = 1
        datas.Cause = value
        message = '已拒绝'
      }
      console.log(this.formData);
      let data = {
        Data: JSON.stringify({
          Modify: {
            system_user_info: [this.formData]
          },
          Add: {
            enterprise_audit_log: [datas]
          }
        }),
        token: $.cookie('token'),
      }

      $.ajax({
        type: 'POST',
        url: DomainName + "/getEditAction",
        data,
        success: function (Result) {
          console.log(Result)
          _this.getList(_this.form)
          _this.$message({
            type: 'success',
            message
          });
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });

    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    delete(Brand_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/ShopBrand_Original',
        type: 'GET',
        async: false,
        data: { action: "jQueryAjax" },
        success: function (res) {
          console.log(res);
          for (let i = 0; i < res.length; i++) {
            if (res[i].Brand_SerialNumber == Brand_SerialNumber) {
              res[i].Row_Status = '1'
              _this.detel = res[i];
            }
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      let data = { Data: JSON.stringify({ Modify: { brand: [_this.detel] } }) };
      console.log(data);
      $.ajax({
        url: DomainName + '/GoodsFileEdit',
        type: 'POST',
        async: false,
        data: data,
        error: function () {
          _this.$message.error("删除失败，请稍后再试")
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    }
  },
})